package com.bkhc.partner.repository;

import com.bkhc.common.util.response.ResultJson;
import com.bkhc.partner.vo.BrandGoodPrice;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.web.client.RestTemplate;

import java.util.List;
import java.util.Map;

@Component
public class ProductRepository {
    @Autowired
    private RestTemplate restTemplate;

    public ResultJson queryProductByBrand(String brandCode,String partnerCode){
        String serviceName = "PRODUCT-APP";
        String url = "http://" + serviceName + "/product/common/brand/products?brandCode="+brandCode+"&partnerCode="+partnerCode;
        ResultJson result = restTemplate.postForObject(url, null, ResultJson.class);
        return result;
    }

    public ResultJson queryBrandProductByPartner(int pageIndex,int pageSize,String partnerCode){
        String serviceName = "PRODUCT-APP";
        String url = "http://" + serviceName + "/product/common/getBrandProductByPartner/"+pageIndex+"/"+pageSize+"?partnerCode="+partnerCode;
        ResultJson result = restTemplate.getForObject(url,  ResultJson.class);
        return result;
    }

    public ResultJson<?> getProductSpec(String productCode) {
        String serviceName = "PRODUCT-APP";
        String url = "http://" + serviceName + "/product/common/brand/product/spec?productCode="+productCode;
        ResultJson result = restTemplate.postForObject(url, null, ResultJson.class);
        return result;
    }

    public ResultJson<?> getBrandProductGood(String productCode, String brandCode) {
        String serviceName = "PRODUCT-APP";
        String url = "http://" + serviceName + "/product/common/brand/product/goods?productCode="+productCode+"&brandCode="+brandCode;
        ResultJson result = restTemplate.postForObject(url, null, ResultJson.class);
        return result;
    }

    public ResultJson<?> getUploadPriceRule(String productCode, String brandCode) {
        String serviceName = "PRODUCT-APP";
        String url = "http://" + serviceName + "/product/common/brand/product/price/rule?productCode="+productCode+"&brandCode="+brandCode;
        ResultJson result = restTemplate.postForObject(url, null, ResultJson.class);
        return result;
    }

    public ResultJson<?> queryUploadPrice(String productCode, String brandCode) {
        String serviceName = "PRODUCT-APP";
        String url = "http://" + serviceName + "/product/common/brand/product/price?productCode="+productCode+"&brandCode="+brandCode;
        ResultJson result = restTemplate.postForObject(url, null, ResultJson.class);
        return result;
    }

    public ResultJson<?> getProduct(String productCode) {
        String serviceName = "PRODUCT-APP";
        String url = "http://" + serviceName + "/product/common/product?productCode="+productCode;
        ResultJson result = restTemplate.postForObject(url, null, ResultJson.class);
        return result;
    }

    public ResultJson<?> getBrand(String brandCode) {
        String serviceName = "PRODUCT-APP";
        String url = "http://" + serviceName + "/product/common/brand?brandCode="+brandCode;
        ResultJson result = restTemplate.postForObject(url, null, ResultJson.class);
        return result;
    }

    public ResultJson<?> uploadPrice(List<BrandGoodPrice> response) {
        String serviceName = "PRODUCT-APP";
        String url = "http://" + serviceName + "/product/common/uploadPrice";
        ResultJson result = restTemplate.postForObject(url, response, ResultJson.class);
        return result;
    }

    public List findByGoodsCodeIn(List<String> goodsCode){
        String serviceName = "PRODUCT-APP";
        String url = "http://" + serviceName + "/product/common/getGoodsCodeListByList";
        List result = restTemplate.postForObject(url, goodsCode, List.class);
        return result;
    }
}
